package com.cxria.pattern.interpreter

String expStr = getExpStr()
Map<String, Integer> var = getValue(expStr)
Calculator cal = new Calculator(expStr)
println "运算结果为:${expStr}=${cal.run(var)}"

String getExpStr() {
    print '请输入表达式:'
    new BufferedReader(new InputStreamReader(System.in)).readLine()
}

Map<String, Integer> getValue(expStr){
    def map = [:]
    for(ch in expStr.toCharArray()){
        if(ch != '+' && ch != '-'){
            if(!map.containsKey(String.valueOf(ch))){
                String input = new BufferedReader(new InputStreamReader(System.in)).readLine()
                map.put(String.valueOf(ch), Integer.valueOf(input))
            }
        }
    }
    map
}